package com.cuixichang.minimalism.core.security.core;

import cn.hutool.json.JSONUtil;
import com.cuixichang.minimalism.basal.base.Result;
import com.cuixichang.minimalism.basal.enums.ResponseCoderEnum;
import org.springframework.http.HttpStatus;
import org.springframework.security.authentication.AccountExpiredException;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class AccountExpiredChain implements ResponseChain{
    @Override
    public boolean matching(Exception e) {
        return e instanceof AccountExpiredException;
    }

    @Override
    public void invoke(HttpServletResponse httpServletResponse, Exception e) throws IOException {
        httpServletResponse.setStatus(HttpStatus.OK.value());
        httpServletResponse.getWriter().write(JSONUtil.toJsonStr(Result.error(ResponseCoderEnum.AccountExpired.getCode()
                ,ResponseCoderEnum.AccountExpired.getDesc())));
    }
}
